package entity

import (
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
	"shqsoft.cn/pas3ui/workflow"
)

//FlowDoing 流程列表
type FlowDoing struct {
	ID         int       `gorm:"primary_key;column:ID"`
	WFID       int       `gorm:"column:WFID"`
	CreateTime time.Time `gorm:"column:CREATETIME"`
	StepID     int       `gorm:"column:STEPID"`
	EMID       int       `gorm:"column:EMID"`
	StartTime  time.Time `gorm:"column:START_TIME"`
	WFNM       string    `gorm:"-"`
	StepName   string    `gorm:"-"`
	PermID     int       `gorm:"-"`
}

//TableName FlowDoing表名
func (FlowDoing) TableName() string {
	return "V_FLOW_DOING"
}

func FlowDoingEF() base.EntityFunc {
	return func() interface{} {
		entity := FlowDoing{}
		return &entity
	}
}
func FlowDoingESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []FlowDoing
		return &entities
	}
}

// AfterFind
func (f *FlowDoing) AfterFind(tx *gorm.DB) (err error) {
	wf := workflow.GetWorkFlow(f.WFID)
	if wf != nil {
		f.WFNM = wf.Name
		f.PermID = wf.PermID
		ac := wf.GetAction(f.StepID)
		if ac != nil {
			f.StepName = ac.Desc
		}
	}
	return
}

func init() {
	base.DaoPoolObj.Put("FlowDoing", base.NewDefaultDao(FlowDoingEF(), FlowDoingESF(), nil, "my"))
}
